package com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bean.Orders;
import com.bean.User;
import com.dao.OrderMapper;
import com.dao.UserMapper;
import com.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WxrStart
 * @create 2022-06-14 14:40
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Orders> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 创建订单
     * @param orders
     * @return
     */
    @Override
    public Integer createOrders(Orders orders) {
     return  orderMapper.insert(orders);
    }

    /**
     * 通过用户查找全部订单(包括商品名字和用户名)
     */
    @Override
    public List<Orders> getOrderByUserId(User user) {
        Integer userId = user.getUserId();
        return orderMapper.getOrderByUserId(userId);

    }

    /**
     * 通过用户查找所有秒杀订单(包括商品名字和用户名)
     * @return
     */
    @Override
    public List<Orders> getOrders(User user) {
        Integer userId = user.getUserId();
        return orderMapper.selectListByAllSeckillOrders(userId);
    }
}
